﻿Public Class TempFile
    Private _FilePath As String = System.IO.Path.GetTempFileName
    Private _Identifier As String = Guid.NewGuid.ToString

    Public Property Data As Byte()

    Public ReadOnly Property FilePath As String
        Get
            Return _FilePath
        End Get
    End Property

    Public ReadOnly Property Identifier As String
        Get
            Return _Identifier
        End Get
    End Property


    Public Sub Create()
        Dim FileStream As New System.IO.FileStream(_FilePath, IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.None, 4096, System.IO.FileOptions.DeleteOnClose)
        Dim Writer As New System.IO.BinaryWriter(FileStream)
        Try
            Writer.Write(_Data)
        Catch ex As Exception
            Trace.WriteLine("TempFile.Create(): " & ex.Message)
        Finally
            Writer.Close()
        End Try
    End Sub

    Public Sub Destroy()
        Try
            System.IO.File.Delete(_FilePath)
        Catch ex As Exception
            Trace.WriteLine("TempFile.Destroy(): " & ex.Message)
        End Try
    End Sub
End Class
